package com.jochen.core.ui

import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.InputListener
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener


fun Actor.onClick(consumer: () -> Unit){
    addListener(object : ClickListener(){
        override fun clicked(event: InputEvent, x: Float, y: Float) {
            consumer()
        }
    })
}

fun <T : Actor> T.onChange(consumer: (T) -> Unit) {
    addListener(object : ChangeListener() {
        override fun changed(event: ChangeEvent, eventActor: Actor) {
            consumer(this@onChange)
        }
    })
}
    